﻿@model SILAS.Entidades.Empleado

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>



@section js{

    <script type="text/javascript">

        $(function () {

            $("#btnGuardar").click(function () {

                var data = $('form').serialize();

                $.post('@Url.Action("Edit", "Empleado")',
                         data,
                         function (ok) {
                             if (ok) {
                                 if (ok.exito == true) {
                                     alert(ok.msg);
                                     window.location = '@Url.Action("ListarEmpleados", "Empleado")';
                                 }
                                 else {
                                     alert(ok.msg);
                                 }
                             }
                         }, "json");
            });

        });
        /*function uploadEmpleadoForm() {
        var data = $('form').serialize();
        //Enviar por post
        $.post('@Url.Action("Edit", "Empleado")', data, insertCallback);
        }

        function insertCallback(data) {
        alert(data);
        }*/



        /*$(function () {
        $("#btncrear").click(function (e) {

        $.post('@Url.Action("Edit", "Empleado")',

        function (ok) {

        if (ok) {
        if (ok.exito == false) {
        alert('No se ha podido guardar');
        }

        else {
        alert('Se guardó correctamente');
        }
        }
        "json"
        }

        );
        });

        });*/

    </script>
}



@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Empleado</legend>
        
        @Html.HiddenFor(model => model.Id)

        <div class="editor-label">
            @Html.LabelFor(model => model.Nombre)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Nombre)
            @Html.ValidationMessageFor(model => model.Nombre)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ApPaterno)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ApPaterno)
            @Html.ValidationMessageFor(model => model.ApPaterno)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ApMaterno)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ApMaterno)
            @Html.ValidationMessageFor(model => model.ApMaterno)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DNI)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DNI)
            @Html.ValidationMessageFor(model => model.DNI)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Area)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Area)
            @Html.ValidationMessageFor(model => model.Area)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Celular)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Celular)
            @Html.ValidationMessageFor(model => model.Celular)
        </div>

        <div class="editor-label">
            @Html.Label("Cargo")
        </div>
        <div class="editor-field">
            @Html.DropDownList("IdCargo")
            @Html.ValidationMessageFor(model => model.IdCargo)
        </div>

        <p>
            <!--input type="submit" value="Save" /-->
            <button id="btnGuardar" type="button">Guardar</button> 
        </p>

        

    </fieldset>
    
    
    <div>
    @Html.ActionLink("Volver a Listar empleados", "ListarEmpleados")
        </div>
}





